<template>
	<view>
		<!-- <view @click="test()">纠错</view> -->
		<scroll-view scroll-y class="homeSwiperContainer">
			<water-mark :meta="meta"></water-mark>
			<analysis :subject="curSubject" :dataIndex="dataIndex" :subjectSize="subjectSize"></analysis>
			<v-analysis :subject="curSubject"></v-analysis>
		</scroll-view>
		<view class="btn" v-if="analyType != 3">
			<view class="btn-left" @click="lastSub()">
				<text class="btn-textl">上一题</text>
			</view>
			<view class="btn-right" @click="nextSub()">
				<text class="btn-text">下一题</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {isEmpty} from '@/utils/index';
	import examService from '@/services/exam/exam';
    import navbarExam from '@/mixins/common/navbar/exam';
    import examCommon from '@/mixins/exam/examCommon';
	import vAnalysis from "./fragments/vanalysis";
	import Analysis from "./fragments/Analysis";
	import userInfo from "@/mixins/index";
	import mixins from '@/mixins/index';
	const service = new examService();
	export default {
        mixins:[navbarExam,examCommon,userInfo,mixins],
		components: {
			vAnalysis,
			Analysis
		},
		computed: {
			subjectDefault() {
				return {
					subjectNum: '',
					choiceType: 1,
					subjectChoices: [],
					subjectDesc: '',
					answer: '',
					selectChoice: [],
				}
			},
            curSubject() {
				return this.subjectDetail.length != 0 ? this.subjectDetail[this.dataIndex] : this.subjectDefault
			}
		},
		
		data() {
			return {
				examId: undefined,
				recordId: undefined,
				paperId: undefined,
				analyType: 1, //3单题解析，2错题解析，1全部解析
				subjectDetail: [],
				dataIndex: 0,
				subjectSize: 0, //试卷题目总数
				realSubjectSize: 0,
				choiceType: 1, // 1 单选 2 多选
				subjectId: undefined,
				searchIndex: 0,
                examBarData: [
                    {
                        img: '/static/exam/examBar02.png',
                        text: '收藏',
                        id: 'collect',
                        type: 'static',
                        onPress: (context) => {
                            context.collectSubject()
                        }
                    },
					{
                    img: '/static/exam/examBar01.png',
                    text: '纠错',
                    id: 'findError1',
                    type: 'static',
                    onPress: (context) => {
                         // console.log("userInfo",JSON.stringify(context.userData))
                         // console.log("banSay",JSON.stringify(context.userData.banSay))
                        //判断用户是否禁言，0未禁言，1禁言
                        if(context.userData.banSay == 0){
                            uni.navigateTo({
                                url:'/pages/exam/errorCollection?subjectId='+context.curSubject.subjectId
                            })
						}else{
                            context.tip("你已经被禁言，禁止纠错")
						}

                    }
                }]
				}
		},
		onLoad(query) {
            // console.log("userInfo",this.userData)
            // console.log("banSay",this.userData.banSay)
			this.examId = query.examId
			this.recordId = query.recordId
			this.analyType = query.analyType
			this.subjectId = query.subjectId //从答题卡进入，选中的特定一题
			this.getAnaly();
		},
        watch:{
            dataIndex:function (newValue) {
                this.reDrawCollect(this);
            }
        },
		methods: {
			test(){
				uni.navigateTo({
				    url:'/pages/exam/errorCollection?subjectId='+this.curSubject.subjectId
				})
			},
			//获取解析数据
			getAnaly() {
				const {
					examId,
					analyType
				} = this;
				let recordId = isEmpty(this.recordId)?'':this.recordId;
				let subjectId = isEmpty(this.subjectId)?'':this.subjectId;
				let self = this;
				service.historyPaperDetail(analyType, examId, recordId, subjectId).then(response => {
					if (response.success) {
						self.subjectDetail = response.result.subjectDetail
						self.subjectSize = response.result.subjectSize
						self.realSubjectSize = self.subjectDetail.length
						self.choiceType = self.subjectDetail[self.dataIndex].choiceType
                        this.reDrawCollect(this);
					} else {
						uni.showToast({
							title: response.message,
							icon: "none",
							duration: 2000
						})
					}
				})
			},
			lastSub() {
				let _this = this
				if (_this.dataIndex != 0) {
					//展示前面一题
					_this.dataIndex--
					_this.choiceType = _this.subjectDetail[_this.dataIndex].choiceType
				} else {
					_this.tip("已经是第一题了")
				}
			},
			nextSub() {
				let _this = this
				if (_this.dataIndex != (Number(_this.realSubjectSize) - 1)) {
					//展示后面一题
					_this.dataIndex++
					_this.choiceType = _this.subjectDetail[_this.dataIndex].choiceType
				} else {
					_this.tip("已经是最后一题了")
				}

			},
			tip(mes) {
				uni.showToast({
					title: mes,
					duration: 2000,
					icon: 'none'
				});
			},
			showModel(mes) {
				if (mes != undefined) {
					uni.showModal({
						title: '提示',
						content: mes,
						success: function(res) {
							if (res.confirm) {
								//console.log('用户点击确定');
							} else if (res.cancel) {
								// console.log('用户点击取消');
							}
						}
					});
				}
			}
		},
	}
</script>

<style lang='scss' scoped>
	.homeSwiperContainer {
		padding-bottom: 80upx;
		height: calc(100vh-80upx);
	}

	.btn {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		text-align: center;
		line-height: 80upx;

		&-left {
			display: inline-block;
			width: 50%;
			height: 80upx;
			background: #fff;
			box-shadow: 0 -1upx 10upx #ccc;
		}

		&-right {
			display: inline-block;
			width: 50%;
			height: 80upx;
			background: #5ea1f8;
			box-shadow: 0 -1upx 10upx #ccc;
		}

		&-textl {
			font-size: 28upx;
			color: #333;
		}

		&-text {
			font-size: 28upx;
			color: #fff;
		}
	}
</style>

<style lang='scss'>
	page {
		height: 100%;
	}
</style>
